package cn.jathlon.ml;

import java.util.Arrays;

import cn.jathlon.math.MathUtils;

/**
 * 标准化向量
 * @author chen
 *
 */
public class Norm {

	/**
	 * 
	 * @param x
	 * @return
	 */
	public static double[] normByMaxMin(double[] x) {

		double[] x_ = x.clone();
		Arrays.sort(x_);
		double max = x_[x.length - 1];
		double min = x_[0];
		double diff = max - min;
		x_ = new double[x.length];
		for (int i = 0; i < x_.length; i++) {
			x_[i] = MathUtils.round((x[i] - min) / diff, 4);
		}
		return x_;
	}
	
	
}
